package com.SMP.service;

import java.util.HashMap;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.SMP.dao.ManagerMapper;
import com.SMP.model.Manager;

@Service
public class LoginService {

	/**
	 * @author WYHY
	 * */
	@Autowired
	ManagerMapper managerMapper;
	
	/**
	 * @author WYHY
	 *@param managerName 用户名
	 *       password 密码
	 * 返回值为1 登录成功
	 * 返回值为2用户名与密码不匹配
	 * 返回值为3用户名不存在
	 * 返回值为4密码为空
	 * 返回值为5用户名为空
	 * */
	public Map login(String managerName,String password) {
		Map map=new HashMap();
		Manager manager=new Manager();
		int sta=0;
		if(managerName.equals("")||managerName.equals(null)){
			sta=5;
		}else if (password.equals("")||password.equals(null)){
			sta=4;
		} else {
			manager=managerMapper.selectByNamePassword(managerName, password);
			Manager manager1=managerMapper.selectByName(managerName);
			if (manager1==null) {
				sta=3;
			} else if (manager==null) {
				sta=2;
			}else if (manager!=null){
				sta=1;
			} 
		}
		map.put("code", sta);
		map.put("manager", manager);
		return map;
	}
}
